package org.smile.design.proxy.reflect;

import org.smile.day01.Human;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Appliction {
    public static void main(String[] args) throws Exception {
        Human tom = new Human();
        tom.move(3);
//        tom.setSsss("ssss");


        Class<?> human = Class.forName("org.smile.day01.Human");
        //Boss bob = Boss.getInstance();


        Method methodMove = human.getDeclaredMethod("move", int.class);
        Method[] ms = human.getMethods();
        for (Method m : ms) {
            if (m.getName().startsWith("get")) {
                m.invoke(tom);
            }
        }


        Class<?>[] s = human.getInterfaces();
        human.getConstructors();
        human.getAnnotations();


        Human stela = (Human) human.newInstance();

        Object o= methodMove.invoke(tom, 6);//tom.move(6)

        Method method = human.getMethod("getI");
        Object o1 = method.invoke(tom);


        Field[] fs = human.getDeclaredFields();
        for (Field f : fs) {
            System.out.println(f.getName());
        }

        System.out.println("=========================");


        Field field = human.getDeclaredField("i");
        System.out.println(field.getDeclaringClass());
        System.out.println(field.getType());
        System.out.println(field.getModifiers() + " -> " + Modifier.toString(field.getModifiers()));


        field.setAccessible(true);
//        field.setInt(tom,18);
//        field.setInt(tom, 23);//tom.i=20;


        Field modifiers = Field.class.getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(field, Modifier.PUBLIC);

        System.out.println(field.getModifiers() + " -> " + Modifier.toString(field.getModifiers()));
        field.setInt(tom, 15);
        System.out.println(field.getInt(tom));
    }
}
